<template>
	<view class="myOrderBox pb10">

		<view class="orderTitle">

			<uv-tabs lineWidth="30" lineColor="#3F7865" :activeStyle="{
			color: '#3F7865',
			fontWeight: 'bold',
			transform: 'scale(1.05)'
    	}" @change="changeOrder" :current="current" :list="list"></uv-tabs>


		</view>
		<view class="mb10" style="height: 90rpx;">

		</view>
		<!-- <view class="cardBox" v-for="(item,index) in orderList" :key="index" @click="toMain(item)"> -->
		<view class="artItem plr16 pt15 pb20  mlr10 mb10 radius6 " v-for="(i,n) in orderList" :key="n"
			@click="toMain(i)">
			<view class="align-center justify-between  pb15 flex1 orderdesc">
				<text class="order">订单编号：{{i.order_no}}</text>
				<text class="status">{{i.status_info}}</text>
			</view>
			<view class=" justify-between align-center mt15 orderdesc pb15">
				<image :src="i.goods_img" mode=""></image>

				<view class="flex-col justify-between flex1" style="height: 173rpx;">

					<view class="title clamp2 mb5">
						{{i.goods_name}}
					</view>
					<view class="">
						<view class="stages">
							¥{{i.show_price}}
						</view>
						<view class="justify-between align-end">
							<text class="money">¥ {{i.order_amount_total}}</text>

						</view>
					</view>
				</view>
			</view>
			<view class="justify-between align-center mt10">
				<image style="width: 56rpx;height: 56rpx;border-radius: 50%;" src="" mode=""></image>
				<view class="wxname">

				</view>
				<view class="cancel" v-if="i.status=='1'" @click.stop="cancelOrder(i)">
					取消订单
				</view>
				<view class="cancel" v-if="i.status=='1'&&i.hetong_status==1" @click.stop="uploadHetong(i)">
					上传合同
				</view>
				<view class="cancel" v-if="i.status!='1'&&i.hetong_status==1" @click.stop="toMain(i)">
					查看合同详情
				</view>
			</view>
		</view>
		<!-- </view> -->
		<view class="" v-if="orderList.length==0">
			<uv-empty mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png"></uv-empty>
		</view>
		<uv-popup ref="popup" :closeable="true" :bgColor="none" :showConfirmButton="false">
			<view class="successBox ">
				<view class="title">上传合同</view>
				<view class="" style="margin: 37rpx 0 35rpx;">
					<view class="align-center flex-wrap justify-start">
						<view class="mr10 mt5 posRelative" v-for="(i,n) in imgList" :key="n">
							<image style="width: 200rpx;height: 200rpx;border-radius: 15rpx;" :src="i" mode=""></image>
							<view @click="del(n)" class="posAbsort" style="right: 10rpx;top: 10rpx">
								<uv-icon name="close-circle"></uv-icon>
							</view>
						</view>
					</view>
					<view v-if="imgList.length<6" class="plus align-center justify-center" @click="uploadImg">
						<uv-icon color="#B0B0B0" size="25" name="plus"></uv-icon>
					</view>
				</view>
				<view class="">
					<uv-textarea v-model="value"
						placeholder="填写签约明细(例如：XX已于X年X月X日X时与XX (网红)签订合同，请平台按照合同内容进行代付)"></uv-textarea>


				</view>
				<view class="confirm" @click="upload">
					确认上传
				</view>
			</view>
		</uv-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleFlag: 1,
				orderList: [],
				hetongid: "",
				page: 1,
				imgList: [],
				value: "",
				list: [{
						name: '全部',
						val: "1"
					},
					{
						name: '待审核',
						val: "6"
					},
					{
						name: '代付中',
						val: "2"
					},
					{
						name: '已取消',
						val: "5"
					},
					{
						name: '未通过',
						val: "11"
					},
					{
						name: '已违约',
						val: "4"
					},
					{
						name: '已完成',
						val: "3"
					},
					{
						name: '已审核',
						val: "12"
					},

				],
				current:0


			};
		},
		onLoad(opt) {
			this.titleFlag = opt.type
			this.current= this.list.findIndex(item=>item.val==opt.type)
			this.getOrder()
		},
		onShow() {
			// if (!uni.getStorageSync('logintoken')) {
			// 	uni.reLaunch({
			// 		url: '/pages/login/login'
			// 	})
			// 	return
			// }

		},
		onReachBottom() {
			if (this.orderList.length < this.total) {
				this.page++
				this.getOrder()
			}
		},
		methods: {

			changeOrder(val) {
				console.log(val)
				this.titleFlag = val.val

				this.page = 1
				this.orderList = []
				this.getOrder()

			},
			formateTime(data) {
				return this.$utils.formatDateTime(data)
			},
			unpaidBtn(type) {

			},
			async getOrder() {
				uni.showLoading({
					title: '加载中'
				})
				let data = await this.$api.orderList({
					page: this.page,
					type_status: this.titleFlag
				})
				uni.hideLoading()
				if (data.code == 1) {
					this.total = data.data.total
					this.orderList = [...this.orderList, ...data.data.rows]
				}

			},
			async uploadImg(e) {
				let vm = this
				uni.chooseImage({
					sourceType: ['album'],
					count: 6 - this.imgList.length,
					success: function(res) {
						console.log(res)
						res.tempFilePaths.map(item => {
							vm.$api.uploadImg({
								filePath: item
							}).then(res => {
								vm.imgList.push(res.data.fullurl)
							})
						})

					}
				})
			},
			upload() {
				if (!this.imgList) return this.$utils.msg('请上传合同')
				this.$api.orderhetong({
					id: this.hetongid,
					images: this.imgList.join(','),
					mingxi: this.value
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						uni.showToast({
							title: '上传成功',
						})
						uni.hideLoading()
						this.$refs.popup.close()
						this.orderList = []
						this.page = 1
						this.getOrder()
					} else {
						this.$utils.msg(res.msg)
					}

				})
			},
			del(n) {
				this.imgList.splice(n, 1)
			},

			toMain(item) {

				uni.navigateTo({
					url: '/pages/orderDetail/index?id=' + item.id + "&status=" + item.status
				})
			},
			uploadHetong(item) {
				this.hetongid = item.id
				this.$refs.popup.open()
			},
			cancelOrder(i) {
				let vm = this
				uni.showModal({
					content: '确定要取消该订单吗',
					success: function(res) {
						if (res.confirm) {

							vm.$api.ordercancel({
								id: i.id
							}).then(res => {
								vm.$utils.msg('操作成功')
								vm.orderList = []
								vm.page = 1
								vm.getOrder()
							})
						}
					}
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.myOrderBox {
		min-height: 100vh;
		position: relative;
		background-color: RGBA(245, 245, 245, 1);

		.orderTitle {
			width: 750rpx;
			height: 90rpx;
			background-color: #FFFFFF;
			// display: flex;
			overflow-x: scroll;
			font-size: 32rpx;
			color: #444;
			position: fixed;
			top: 0;

			// border-bottom: 2rpx solid  rgba(151,151,151,0.062);
			.titleItem {
				height: 90rpx;
				line-height: 90rpx;
				text-align: center;
				flex-basis: 0rpx;
				flex-grow: 1;
				font-weight: 500;
				width: 200rpx;
				display: inline-block;
			}

			.active {
				height: 90rpx;
				line-height: 90rpx;
				text-align: center;
				flex-basis: 0rpx;
				flex-grow: 1;
				color: #3F7865;
				display: inline-block;
				position: relative;
				font-weight: 500;
			}

			.active::after {
				position: absolute;
				content: "";
				width: 49rpx;
				height: 8rpx;
				background: #3F7865;
				border-radius: 4rpx;
				bottom: 0rpx;
				left: 50%;
				transform: translateX(-50%);

			}
		}

	}

	.submitPz {
		width: 165rpx;
		height: 54rpx;
		background: #434343;
		border-radius: 6rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 54rpx;
	}

	.artItem {

		background-color: #fff;
		font-size: 28rpx;
		color: #999999;

		image {
			width: 237rpx;
			height: 173rpx;
			border-radius: 8rpx;
			margin-right: 26rpx;
		}

		.title {
			font-weight: bold;
			font-size: 30rpx;
			color: #222222;
		}

		.orderdesc {
			border-bottom: 1rpx solid #EFEFEF;
		}

		.stages {
			border-radius: 5rpx;
			border: 1px solid #3F7865;
			color: #3F7865;
			font-size: 22rpx;
			display: inline-block;
			line-height: 22rpx;
			padding: 5rpx 8rpx;
			margin-bottom: 16rpx;
		}

		.money {
			font-weight: 500;
			font-size: 34rpx;
			color: #333333;
		}

		.cancel {
			width: 180rpx;
			height: 60rpx;
			background: #3F7865;
			border-radius: 60rpx;
			font-weight: 500;
			font-size: 28rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 60rpx;
		}
	}

	.plus {
		width: 200rpx;
		height: 200rpx;
		background: #F5F5F7;
		border-radius: 15rpx;
	}

	.successBox {
		width: 660rpx;
		// height: 700rpx;
		background: #fff;
		border-radius: 28rpx;
		font-size: 28rpx;
		color: #A4A4A4;
		padding: 40rpx;

		.title {
			font-weight: 500;
			font-size: 36rpx;
			color: #333333;
			text-align: center;
		}

		.success {
			font-weight: bold;

			margin: 38rpx 0;
		}

		.confirm {
			width: 586rpx;
			height: 90rpx;
			background: #3F7865;
			border-radius: 15rpx;
			font-size: 36rpx;

			color: #fff;

			margin-top: 126rpx;
			line-height: 90rpx;
			text-align: center;
		}
	}
</style>